import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Home from '@/views/Home'
import User from '@/views/User'
import Video from '@/views/Video'
import Search from '@/views/Search'
import SearchResult from '@/views/Search/SearchResult'

Vue.use(VueRouter)

const routes = [
  { path: '/login', component: Login },
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '',
        component: Home
      },
      {
        path: 'video',
        component: Video
      },
      {
        path: 'user',
        component: User
      }
    ]
  },
  { path: '/search', component: Search },
  { path: '/searchResult', component: SearchResult }
]
const router = new VueRouter({
  routes
})

// 导航守卫
// router.beforeEach((to, from, next) => {
//   // console.log(Date.now(), '路由跳转')
//   console.log(to, from, next)
//   // 如果你要去的页面是 "VIP" 页面
//   const pageList = ['/', 'home', 'video', 'user']
//   // if (to.path === '/image' || to.path === '/article') {
//   if (pageList.includes(to.path)) {
//     // 1. 获取token
//     const tokenStr = localStorage.getItem('hmtt')
//     if (tokenStr) {
//       next() // 放行
//     } else {
//       console.log('没有token')
//       next('/login')
//     }
//   } else {
//     next() // 放行
//   }
// })

export default router
